<template>
    <div class="calculator">
        <cal-result
                :result="result"
        ></cal-result>

        <div class="inputs">
            <cal-input type="oneNumber" @dispatch="dispatch"
            ></cal-input>
            <cal-input type="twoNumber" @dispatch="dispatch"
            ></cal-input>
        </div>

        <div class="buttons">
            <cal-button type="jia" val="+"
                        :curMethod="curMethod"
                        @dispatch="dispatch"
            ></cal-button>
            <cal-button type="jian" val="-"
                        :curMethod="curMethod"
                        @dispatch="dispatch"
            ></cal-button>
            <cal-button type="cheng" val="*"
                        :curMethod="curMethod"
                        @dispatch="dispatch"
            ></cal-button>
            <cal-button type="chu" val="/"
                        :curMethod="curMethod"
                        @dispatch="dispatch"
            ></cal-button>
        </div>
    </div>
</template>

<script>
    import CalResult from "./Result";
    import CalInput from "./Input";
    import CalButton from "./Button";

    import dispatch from '../../dispatchers/calculator';

    export default {
        name: "calculator",
        components: {CalResult, CalInput, CalButton},
        data() {
            return {
                result: 0,

                oneNumber: 0,
                twoNumber: 0,
                curMethod: "jia"
            }
        },
        methods: {
            /*
            主要是两个方法：
            计算结果
            更换计算符号
            * */
            dispatch(...arg) {
                dispatch(this)(...arg);
            }


            // setNumber(type,val){
            //   this[type] = val;
            //   this.compute(this.curMethod,this.oneNumber,this.twoNumber);
            // },
            // changeMethod(method){
            //   this.curMethod = method;
            //   this.compute(this.curMethod,this.oneNumber,this.twoNumber);
            // },
            // compute(type,oneNum,twoNum){
            //     switch (type) {
            //         case 'jia':
            //             this.result = oneNum + twoNum;
            //             break;
            //         case 'jian':
            //             this.result = oneNum - twoNum;
            //             break;
            //         case 'cheng':
            //             this.result = oneNum * twoNum;
            //             break;
            //         case 'chu':
            //             this.result = oneNum / twoNum;
            //             break;
            //         default:
            //             break;
            //     }
            // }
        }
    }
</script>

<style scoped>

</style>
